import 'package:flutter/material.dart';
import 'package:flutter_widget/src/widget/effect/clip_widget.dart';

///卡片效果
class CardWidget extends StatelessWidget {
  final double? width;
  final double? height;
  final double radius; //圆角大小
  final Widget? child; //子控件
  final Color? backgroundColor; //背景色
  final Color? shadowColor; //阴影颜色
  final double shadowElevation; //阴影模糊程度
  final Offset? shadowOffset; //默认y轴偏移1px
  final double spreadRadius; //阴影扩散的程度 取值可以正数,也可以是负数,默认0
  final DecorationImage? image;
  final BorderRadiusGeometry? borderRadius;

  const CardWidget({
    Key? key,
    this.width,
    this.height,
    this.radius = 4,
    this.child,
    this.shadowOffset,
    this.shadowElevation = 10,
    this.spreadRadius = 0,
    this.shadowColor,
    this.backgroundColor,
    this.image,
    this.borderRadius,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      height: height,
      decoration: BoxDecoration(
        boxShadow: [
          //阴影效果
          BoxShadow(
            offset: shadowOffset ?? const Offset(0, 1), //阴影在X轴和Y轴上的偏移
            color: shadowColor ?? Colors.black.withOpacity(0.05), //阴影颜色
            blurRadius: shadowElevation, //阴影程度
            spreadRadius: spreadRadius, //阴影扩散的程度
          ),
        ],
        color: backgroundColor ?? Colors.white,
        borderRadius: borderRadius ?? BorderRadius.circular(radius),
        image: image,
      ),
      // margin: EdgeInsets.all(0),
      child: radius == 0
          ? child
          : ClipWidget(
              radius: (radius),
              child: child,
            ),
    );
  }
}
